#!/bin/bash

echo "开始升级"
# 获取压缩包文件名
archive=$1
filename="update.tmp"

# 生成文件
touch "$filename"
# 解压的目标目录
path="update"

# 升级脚本
update="upgrade.sh"

#绝对路径
current_path=$(pwd)/update

# 打印并执行命令
command="pwd"

# 检查文件是否存在
if [ ! -f "$archive" ]; then
  echo "Error: Archive file '$archive' not found." > "$filename"
  exit 1
fi
# 解压文件
tar -xzvf "$archive" -C "$path"

cd "$path/EagleEyeSMG"

echo "执行命令：$command"
eval "$command"

#mv Upgrade/* .

# 检查升级脚本是否存在
if [ ! -f "$update" ]; then
  echo "Error: Can't find Upgrade file" > "../../$filename"
  exit 1
fi

source "$current_path"/EagleEyeSMG/upgrade.sh
#等程序执行执行结束
wait

#echo "升级结束"
#cd ../../
#rm -rf update

echo "执行完成"